<?php

namespace Biz\service\advertisement\apiModule;

use Biz\model\advertisement\MPositionBaseInfo;
use Doraemon\model\Position\PositionExtend;
use Doraemon\service\statSign\Basic as basicStatSign;
use Doraemon\tools\BlockType;
use Doraemon\tools\ImgUrl;
use Doraemon\tools\LinkFormat;

class ImMsgListBanner extends BaseModule
{

    const FORMAT_HIT = 'formatPosHit';

    public function format($hit, $uid, $userProfileExt, $statSignExt)
    {
        $response = [];
        foreach ($hit as $k => $v) {
            $link = $this->generateLink($v['link_type'], $v['link_params']);
            $title = $v['ext'] ? $v['ext']['title'] : '';
            switch ($v["reason"]) {
                case  MPositionBaseInfo::REASON_TYPE_BUSINESS:
                case  MPositionBaseInfo::REASON_TYPE_KA:
                    $tag = "https://img.haohaozhu.cn/Op-imageShow/61a23302u01c0A700s3qvbd?iv=1";
                    break;
                case  MPositionBaseInfo::REASON_TYPE_OPERATE:
                    $tag = "https://img.haohaozhu.cn/Op-imageShow/59e39302u01c0BF00s3qvbd?iv=1";
                    break;
                case  MPositionBaseInfo::REASON_TYPE_SUPER:
                case  MPositionBaseInfo::REASON_TYPE_NEW_USER:
                case  MPositionBaseInfo::REASON_TYPE_PRODUCT:
                default:
                    $tag = "https://img.haohaozhu.cn/Op-imageShow/b954a302u01c0FC00s3qvbd?iv=1";
                    break;
            }
            $response[] = [
                'id' => intval($v['id']),
                'title' => $title,
                'sub_title' => $v['ext'] ? $v['ext']['key_word'] : '',
                'icon' => empty($v['pic_id']) ? '' : ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $v['pic_id'], ImgUrl::IMAGE_SIZE_OP_ORI),
                'tag' => $tag,
                'link' => $link,
                'statSign' => $this->statSign($v, [], ['title' => $title, 'link' => $link]),
            ];
        }
        return $response;
    }

    public function uniquePos($v): string
    {
        return $v['pos'];
    }
}